package com.example.demo.controller;

import com.example.demo.entity.Customers;
import com.example.demo.service.CustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customers")
public class CustomersController {

    @Autowired
    private CustomersService customersService;

    @GetMapping
    public List<Customers> getAllCustomers() {
        return customersService.list();
    }

    @GetMapping("/{id}")
    public Customers getCustomerById(@PathVariable Integer id) {
        return customersService.getById(id);
    }

    @PostMapping
    public boolean createCustomer(@RequestBody Customers customer) {
        return customersService.save(customer);
    }

    @PutMapping("/{id}")
    public boolean updateCustomer(@PathVariable Integer id, @RequestBody Customers customer) {
        customer.setCustomerId(id); // 假设实体中有setCustomerId方法
        return customersService.updateById(customer);
    }

    @DeleteMapping("/{id}")
    public boolean deleteCustomer(@PathVariable Integer id) {
        return customersService.removeById(id);
    }
}
